/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ptr.ptrsystem.ajax;

import com.ptr.controladores.conexionsqlserver;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author pavel
 */
@WebServlet(name = "nacimiento", urlPatterns = {"/nacimiento"})
public class nacimientoservlet extends HttpServlet {

    public nacimientoservlet() {
    }

conexionsqlserver base=new conexionsqlserver();
String ubigeoOR;
String DNIMaterno;
String DNIPaterno;
String Ddec1;
String Ddec2;
String DReg;
String ubid;
String UbigeoOR;
        Connection conn;
        Statement st;
        ResultSet rs;
        ResultSet rs3;
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

       ubigeoOR=request.getParameter("UBIOR");
                DNIMaterno=request.getParameter("txt_DniUMat");
                DNIPaterno=request.getParameter("txt_DniUPat");
                Ddec1=request.getParameter("txtDdec1");
                Ddec2=request.getParameter("txtDdec2");
                DReg=request.getParameter("txtDReg");
       if(ubigeoOR!=null)
        {
            try
            {
                base.conectar();
                conn=base.getconection();
                st=conn.createStatement();
                String query8="select * from TB_UBIGEO";
                query8=query8+" where idubigeo='"+ubigeoOR+"'";
                ResultSet rsu=st.executeQuery(query8);
                if(rsu.next())
                {
                    out.println(rsu.getString(6)+" / "+rsu.getString(7)+" / "+rsu.getString(8)+" / "+rsu.getString(9));
                }else
                {out.println("No existe el ubigeo selecccionado");}
            }
            catch(SQLException er)
            {er.printStackTrace();}
        }
       if(DNIMaterno!=null)
        {
            try
            {
                base.conectar();
                conn=base.getconection();
                st=conn.createStatement();
                String query9="SELECT * FROM TB_PERSONA";
                query9=query9+" WHERE CUI_PERS='"+DNIMaterno+"'";
                ResultSet rsd=st.executeQuery(query9);
                if(rsd.next())
                {
                    out.println(rsd.getString(4)+" "+rsd.getString(5)+" "+rsd.getString(6)+" "+rsd.getString(7));
                }else
                {out.println("No existe el DNI que desea Buscar");}
            }
            catch(SQLException usu)
            {out.println("Error en la Busqueda de Persona: "+usu.getMessage());}
        }
       if(DNIPaterno!=null)
        {
            try
            {
                base.conectar();
                conn=base.getconection();
                st=conn.createStatement();
                String query10="SELECT * FROM TB_PERSONA";
                query10=query10+" WHERE CUI_PERS='"+DNIPaterno+"'";
                ResultSet rsp=st.executeQuery(query10);
                if(rsp.next())
                {
                    out.println(rsp.getString(4)+" "+rsp.getString(5)+" "+rsp.getString(6)+" "+rsp.getString(7));
                }else
                {out.println("No existe el DNI que desea Buscar");}
            }
            catch(SQLException usu)
            {out.println("Error en la Busqueda de Persona: "+usu.getMessage());}
        }
/////////////////  Declarante 1
       if(Ddec1!=null)
        {
            try
            {
                base.conectar();
                conn=base.getconection();
                st=conn.createStatement();
                String query11="SELECT * FROM TB_PERSONA";
                query11=query11+" WHERE CUI_PERS='"+Ddec1+"'";
                ResultSet rsd1=st.executeQuery(query11);
                if(rsd1.next())
                {
                    out.println(rsd1.getString(4)+" "+rsd1.getString(5)+" "+rsd1.getString(6)+" "+rsd1.getString(7));
                }else
                {out.println("No existe el DNI que desea Buscar");}
            }
            catch(SQLException usu)
            {out.println("Error en la Busqueda de Persona: "+usu.getMessage());}
        }  
/////// Declarante 2
       if(Ddec2!=null)
        {
            try
            {
                base.conectar();
                conn=base.getconection();
                st=conn.createStatement();
                String query12="SELECT * FROM TB_PERSONA";
                query12=query12+" WHERE CUI_PERS='"+Ddec2+"'";
                ResultSet rsd2=st.executeQuery(query12);
                if(rsd2.next())
                {
                    out.println(rsd2.getString(4)+" "+rsd2.getString(5)+" "+rsd2.getString(6)+" "+rsd2.getString(7));
                }else
                {out.println("No existe el DNI que desea Buscar");}
            }
            catch(SQLException usu)
            {out.println("Error en la Busqueda de Persona: "+usu.getMessage());}
        }  
///// DNI Registrador 
              if(DReg!=null)
        {
            try
            {
                base.conectar();
                conn=base.getconection();
                st=conn.createStatement();
                String query13="SELECT * FROM TB_PERSONA";
                query13=query13+" WHERE CUI_PERS='"+DReg+"'";
                ResultSet rsr=st.executeQuery(query13);
                if(rsr.next())
                {
                    out.println(rsr.getString(4)+" "+rsr.getString(5)+" "+rsr.getString(6)+" "+rsr.getString(7));
                }else
                {out.println("No existe el DNI que desea Buscar");}
            }
            catch(SQLException usu)
            {out.println("Error en la Busqueda de Persona: "+usu.getMessage());}
        }             
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
